<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>邀请码-思多客</title>
    <link href="http://cdn.bootcss.com/normalize/7.0.0/normalize.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/public/css/m/public.css">
    <style>
        .invite-content{
            margin: 0.48rem 0;
            padding: 0.5rem 0.4rem;
            font-size: 0.4rem;
        }
        .invite-content li{
            line-height: 1.5;
        }
        .my-invide-code{
            width: 2.4rem;
        }
        .invite-save-btn{
            display: inline-block;
            width: 1.066rem;
            line-height: 1.5;
            color: #fff;
            background-color: #ff0000;
            font-size: 0.4rem;
            margin-left: 0.13rem;
            vertical-align: middle;
            outline: none;
            border: none;
        }
    </style>
</head>

<body>
    <div class="n-page">
        <div class="new-header flex">
            <div class="back-box">
                <img src="/public/images/m/back.png" alt="" class="left-back-icon">
            </div>
            <span class="header-title flex-child-box">邀请码</span>
        </div>
        <div class="content invite">
            <div class="center-logo-box">
                <img src="/public/images/m/logo-h.png" alt="" class="logo-icon">
                <span>传播智慧,&nbsp;传承分享</span>
            </div>
            <div class="invite-content">
                <ul id="J_invite"></ul>
            </div>
        </div>
        <div id="footer"></div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/public/js/m/fontResize.js"></script>
    <script src="/public/lib/layer/layui.js"></script>
    <script src="/public/js/G.js"></script>
    <script src="/public/js/user.js"></script>
    <script src="/public/js/m/public.js"></script>
    <script id="T_inviteTpl" type="text/html">
        <li>
            <div id="myInviteCode" class="{{# if(d.inviteCode){ }} show {{# }else{ }} hide {{# }; }}">
                邀请码：<span id="myInvite">{{formatVal(d.inviteCode)}}</span>
            </div>
            <div id="myInviteCodeContent" class="{{# if(d.inviteCode){ }} hide {{# }else{ }} show {{# }; }}">
            <label for="inviteCode">填写邀请码：</label>
            <input type="text" class="my-invide-code" id="inviteCode">
            <input type="button" value="保存" class="invite-save-btn" id="saveInvite">
            </div>
        </li>
        <li>客户邀请码：{{d.exclusiveInviteCode}}</li>
        <li>业务邀请码：{{formatVal(d.commissionInviteCode)}}</li>
    </script>
    <script>
    layui.use('laytpl', function() {
        var laytpl = layui.laytpl;

        isLogined('user.html')
        user.getInfo({}, function(data) {
            console.log(data)
            laytpl($('#T_inviteTpl').html()).render(data, function(html) {
                $('#J_invite').html(html)
            })
            lazyload()
        })
    })
    $(document).on('click','#saveInvite',function(){
        var inviteCode = $('#inviteCode').val().trim();
        console.log(inviteCode)
        if(!inviteCode){
            return;
        }
        user.setInviteCode({inviteCode: inviteCode},function(){
            alert('设置成功')
            $('#myInvite').html(inviteCode)
            $('#myInviteCode').show()
            $('#myInviteCodeContent').hide()
        },function(err){
            alert(err)
        })
    })
    </script>
</body>

</html>